﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MVVMLightDemo.ViewModel
{
    public class ComplexCheckViewModel:ViewModelBase
    {
        public List<ComplexCheckModel> ListCheckModels { get; set; }

        public RelayCommand CheckCommand { get; set; }

        private string selectedObjects;

        public string SelectedObjects
        {
            get { return selectedObjects; }
            set
            {
                selectedObjects = value;
                this.RaisePropertyChanged("SelectedObjects");
            }
        }


        public ComplexCheckViewModel()
        {
            ListCheckModels = new List<ComplexCheckModel>
            {
                new ComplexCheckModel{Content = "香蕉",IsCheck = false},
                new ComplexCheckModel{Content = "梨子",IsCheck = false},
                new ComplexCheckModel{Content = "西瓜",IsCheck = false},
                new ComplexCheckModel{Content = "菠萝",IsCheck = false}
            };

            CheckCommand = new RelayCommand(() => 
            {
                SelectedObjects = String.Empty;
                ListCheckModels.ForEach(n =>
                {
                    if(n.IsCheck == true)
                    {
                        SelectedObjects += n.Content + " ";
                    }
                });
            });



        }
    }
}
